Skip to content

wqueue: Support custom user work queues. - #19982

Open
13022591351 wants to merge 4 commits into
apache:masterfrom
13022591351:feature/custom-user-wqueue
Open

wqueue: Support custom user work queues.#19982
13022591351 wants to merge 4 commits into
apache:masterfrom
13022591351:feature/custom-user-wqueue

Conversation

@13022591351

@13022591351 13022591351 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add dynamically created user-mode work queues for Protected and Kernel
    builds through the existing handle-based work queue API.
  • Implement configurable pthread worker pools in libs/libc/wqueue while
    retaining the predefined USRWORK queue.
  • Harden scheduler custom queue lifecycle handling so both backends reject
    submissions during teardown, release pending work ownership, wait for all
    workers, clean up partial creation, and synchronously cancel every callback
    using the same work_s.
  • Align delay validation, pending replacement, periodic requeue, priority,
    and idempotent cancellation behavior between scheduler and libc backends.
  • Document the custom queue APIs and explicitly restrict libc user work queue
    calls to task context; they must not be called from an ISR.
  • Related test PR: testing/ostest: Exercise custom work queues. nuttx-apps#3759.
  • Related STM32H7 hardware-enablement PR: stm32h7: Fix Protected user SRAM placement and attributes. #19983.

Commit organization

b817fb59b5 sched/wqueue: Harden custom queue lifecycle.
7d31e87df1 libc/wqueue: Support custom user work queues.
5be853a5eb libc/wqueue: Use the uninterruptible wait helper.
d3b65e96ce Documentation/wqueue: Document custom user queues.

The libc functional commit deliberately contains an explicit
nxsem_wait() retry on -EINTR. The next master-only cleanup commit replaces
that loop with nxsem_wait_uninterruptible() and produces the same behavior.
An older release branch where that helper is not available to Protected user
space can therefore cherry-pick the scheduler and libc functional commits,
omit only the helper cleanup, and take the documentation commit without a
downstream-only compatibility patch.

Please keep the functional and helper-cleanup commits separate for that
reason. If a squashed history is preferred, that older PX4 release branch
will not be supported by this series rather than carrying a special NuttX
patch downstream.

Impact

  • New feature: YES. Protected/Kernel user processes can create independent
    work queues with configurable priority, stack size, and worker count.
  • User adaptation: NO. Existing USRWORK, HPWORK, and LPWORK users
    remain supported. New user custom-queue APIs are task-context only.
  • Build process: NO. No new configuration symbol or build step is added.
  • Hardware: NO. The work queue implementation is architecture-independent.
  • Documentation: YES. Documentation/reference/os/wqueue.rst and public
    header comments describe custom queues, teardown, errors, and execution
    context.
  • Security: NO known impact.
  • Compatibility: No source or ABI break. Idle libc cancellation is now a
    successful no-op, matching the scheduler backend's existing behavior.

Testing

Build host:

  • Linux 6.8.0-60-generic, x86_64
  • GNU Arm Embedded Toolchain 10.3.1 20210824

Target:

  • ARM Cortex-M7, STM32H7, PX4 FMUv6C
  • Apache NuttX master c6b349b0234466a54a624ae35ba77adb73a9ea0e
  • Flat and Protected builds; the Protected hardware test also contains the
    patch-equivalent STM32H7 Protected-memory series from stm32h7: Fix Protected user SRAM placement and attributes. #19983.
  • Both configurations were rebuilt after make distclean, uploaded through
    the PX4 bootloader, and tested through USB NSH with minicom.

Before change:

The libc user backend only provides the predefined USRWORK queue. A
Protected user application using work_queue_create(), work_queue_free(), or
the handle-based queue/cancel APIs cannot link a custom user queue backend.

Build output after change:

master_flat:
  FLASH     1470396 B / 1920 KB (74.79%)
  AXI_SRAM    63380 B / 512 KB  (12.09%)

master_protected kernel:
  kflash      877528 B / 896 KB (95.64%)
  ksram        54320 B / 128 KB (41.44%)

master_protected user:
  uflash      751000 B / 1 MB   (71.62%)
  usram         8192 B / 384 KB (2.08%)

Runtime commands and results, three runs per backend:

nsh> time "ostest wqueue"
Flat:             30.1490 / 30.1490 / 30.1480 s
Protected user:  15.6540 / 15.6540 / 15.6550 s

nsh> time "wqueue_test_kernel"
Protected kernel: 30.1480 / 30.1490 / 30.1490 s

Steady-state memory after the first run remained unchanged through all later
runs:

Flat:       Umem used 14600 B, 58 used / 5 free nodes
Protected:  Kmem used 10104 B, 50 used / 4 free nodes
            Umem used  9232 B, 14 used / 4 free nodes

Every run covered one- and two-worker custom queues, explicit caller
priorities, invalid arguments, periodic requeue, pending replacement,
synchronous cancellation, two concurrent callbacks using one work_s, four
simultaneous queues with 32 work items, self-destruction rejection, and
pending/running teardown. All assertions passed, heap usage did not grow, and
all custom worker pools completed teardown.

The final PR WQ source tree matches the runtime-tested source tree.

Validation:

tools/checkpatch.sh -m -g upstream/master..feature/custom-user-wqueue: pass
tools/checkpatch.sh -g upstream/master..feature/custom-user-wqueue: pass
git diff --check upstream/master..feature/custom-user-wqueue: pass
pre/post split path-limited git diff --exit-code: identical

The documentation HTML build was not run locally because sphinx-build is
not installed on the build host.

PR verification Self-Check

  • This PR introduces only one functional change.
  • I have updated all required description fields above.
  • My PR adheres to the contributing guidelines and coding standard.
  • My PR is still work in progress.
  • My PR is ready for review and can be safely merged.

@github-actions github-actions Bot added Area: Documentation Improvements or additions to documentation Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels Aug 27, 2026
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

qemu-armv8a

  • Code: .rodata +48 B, .text.work_qcancel +48 B, .text.work_queue_create +56 B, .text.work_queue_free +300 B, .text.work_queue_wq +16 B, .text.work_thread +36 B, .text.work_thread_create +360 B (+0.3%, 320,676 B)

stm32-nucleo-f103rb

@13022591351

Copy link
Copy Markdown
Contributor Author

Updated the series organization and repeated the complete master hardware
validation on PX4 FMUv6C.

The series is now split into scheduler functionality, libc functionality with
the explicit nxsem_wait() EINTR retry, a separate master cleanup using
nxsem_wait_uninterruptible(), and RST documentation. Please keep the libc
functional and helper-cleanup commits separate; the rationale and selective
release-branch path are documented in the PR description.

Fresh make distclean build results:

master_flat:
  FLASH     1470396 B / 1920 KB (74.79%)
  AXI_SRAM    63380 B / 512 KB  (12.09%)

master_protected kernel:
  kflash      877528 B / 896 KB (95.64%)
  ksram        54320 B / 128 KB (41.44%)

master_protected user:
  uflash      751000 B / 1 MB   (71.62%)
  usram         8192 B / 384 KB (2.08%)

Three USB NSH runs per backend:

Flat kernel:      30.1490 / 30.1490 / 30.1480 s
Protected user:  15.6540 / 15.6540 / 15.6550 s
Protected kernel: 30.1480 / 30.1490 / 30.1490 s

All assertions passed. Steady-state heap usage remained unchanged after the
first run: Flat Umem 14,600 B; Protected Kmem 10,104 B and Umem 9,232 B. All
custom worker pools completed teardown.

The final PR WQ source tree matches the runtime-tested source tree. Full-range
commit-message checkpatch, code checkpatch, and git diff --check all pass.

Comment thread sched/wqueue/kwork_cancel.c Outdated
Comment thread libs/libc/wqueue/work_usrthread.c
Comment thread libs/libc/wqueue/work_usrthread.c Outdated
Comment thread libs/libc/wqueue/work_usrthread.c Outdated
Comment thread libs/libc/wqueue/work_usrthread.c Outdated
Comment thread libs/libc/wqueue/work_queue.c Outdated
Comment thread libs/libc/wqueue/work_queue.c Outdated
Comment thread libs/libc/wqueue/work_queue.c Outdated
Comment thread sched/wqueue/kwork_queue.c Outdated
Comment thread sched/wqueue/kwork_queue.c Outdated
Prevent work_queue_free() from destroying predefined queues or freeing a
custom queue from one of its own callbacks.  Mark teardown under the queue
lock, reject new submissions, return pending work to its owner, and wait for
every worker before releasing queue resources.

Clean up partially created worker pools, reject invalid delays, safely
replace pending periodic work, and make synchronous cancellation wait for
every concurrent callback using the same work structure.

Tested on an STM32H7 PX4 FMUv6C with the matching ostest suite in Flat and
Protected kernel builds.

Assisted-by: Codex:GPT-5
Signed-off-by: DuoYuWang <thirteenking.wang@gmail.com>
Implement the handle-based create, queue, priority, cancellation, and
teardown APIs for CONFIG_LIBC_USRWORK.  Custom queues use configurable
pthread worker pools while the predefined USRWORK queue remains available.

Match scheduler-backend delay, replacement, cancellation, and lifecycle
semantics.  Restrict the libc backend to task context because it uses
blocking synchronization.

Tested on an STM32H7 PX4 FMUv6C with ostest wqueue in Protected user space.

Assisted-by: Codex:GPT-5
Signed-off-by: DuoYuWang <thirteenking.wang@gmail.com>
Replace the local EINTR retry loop with nxsem_wait_uninterruptible().
This keeps the master implementation aligned with the libc semaphore API
without changing cancellation behavior.

Keep the cleanup separate so release branches where the helper is not
available to Protected user space can use the functional commit without a
downstream compatibility patch.

Assisted-by: Codex:GPT-5
Signed-off-by: DuoYuWang <thirteenking.wang@gmail.com>
Describe the handle-based custom queue APIs, worker-pool creation and
teardown, periodic requeue, cancellation semantics, and return values.

Clarify that libc user work queue APIs use blocking synchronization and
must only be called from task context, while kernel and Flat queue and
asynchronous cancellation operations remain ISR-safe.

Assisted-by: Codex:GPT-5
Signed-off-by: DuoYuWang <thirteenking.wang@gmail.com>
@13022591351
13022591351 force-pushed the feature/custom-user-wqueue branch from d3b65e9 to 9fc4184 Compare August 29, 2026 13:22
@13022591351
13022591351 requested a review from yamt as a code owner August 29, 2026 13:22
@13022591351

Copy link
Copy Markdown
Contributor Author

I force-pushed the branch after applying the inline review feedback and
rebasing the series onto current Apache NuttX master
5d2ed54d26e293a5eea870d9458e36d0d02083fb.

The updated commit series is:

c4ccf265d0 sched/wqueue: Harden custom queue lifecycle.
19898d78d4 libc/wqueue: Support custom user work queues.
917659e44b libc/wqueue: Use the uninterruptible wait helper.
9fc4184667 Documentation/wqueue: Document custom user queues.

Review fixes

The updated series addresses all 16 inline review comments:

  • Reordered the local declarations in the scheduler cancellation path.
  • Configured the predefined pthread worker as detached through
    pthread_attr_setdetachstate() and removed the separate detach call.
  • Moved pthread attribute destruction after thread creation.
  • Kept the predefined queue and worker state in their static initializers and
    removed redundant runtime reinitialization.
  • Kept the predefined USRWORK queue at one worker; configurable multi-worker
    pools remain limited to queues created by work_queue_create().
  • Renamed the worker argument consistently and merged the intermediate worker
    wrapper into work_pthread().
  • Restored the removed source section headers.
  • Wrapped the delay validation conditions as requested in both scheduler queue
    entry points and the libc entry point.
  • Replaced direct list manipulation with work_remove(). Both the queue and
    cancel paths call it while holding the corresponding queue lock, so pending
    replacement remains atomic.
  • Documented the work_remove() lock and queue-ownership requirements in both
    backends.
  • Expanded the zero-delay wake comment: an immediately runnable item may be
    inserted behind another ready item, so another idle worker should be woken
    without waiting for the first worker to dequeue the current head.

Additional changes beyond the literal inline suggestions

I also included the following compatibility and robustness corrections found
while validating the review changes:

  • Changed libc worker identifiers from pthread_t handling to NuttX pid_t
    handling with gettid() and sched_getparam().
  • Preserved the predefined Protected USRWORK queue when
    CONFIG_DISABLE_PTHREAD=y. In this configuration, pthread-backed custom
    queue APIs are excluded while predefined queue-ID APIs remain available.
  • Updated Kconfig, public header comments, and the work queue documentation to
    describe that custom user queues require pthread support.
  • Added pthread_attr_getschedparam() before changing a custom worker's
    priority. This initializes the complete struct sched_param and avoids
    passing uninitialized sporadic-scheduling fields when
    CONFIG_SCHED_SPORADIC=y.
  • Kept the nxsem_wait_uninterruptible() cleanup in a separate commit so the
    functional commits remain independently backportable to an older branch
    where that helper is unavailable to Protected user space.

The last scheduling-parameter initialization change is six lines in
work_thread_create(). The Protected image was rebuilt after this change.
The test target does not enable CONFIG_SCHED_SPORADIC, so its runtime
scheduling behavior is unchanged.

Test coverage

All full work queue runs cover:

  • HPWORK and LPWORK where available;
  • custom queues with one and two workers;
  • invalid arguments and idle cancellation;
  • callback-driven periodic requeue;
  • pending work replacement;
  • synchronous cancellation;
  • two concurrent callbacks using one work_s;
  • four simultaneous queues with eight work items each and worker pools of
    one, two, three, and four threads;
  • callback self-destruction rejection;
  • pending and running queue teardown;
  • rejection of requeue attempts after teardown starts.

1. Flat

Build output:

Flash:    143,956 B
AXI SRAM:  34,468 B

Three ostest wqueue runs:

30.1490 / 30.1480 / 30.1480 s

After the first run, Umem remained stable at:

14,000 B used / 835,512 B free
55 used / 6 free allocation nodes

The first run retained 32 bytes of one-time process state. The following two
runs showed no cumulative memory growth.

2. Protected

Build output:

Kernel: 89,848 B kflash; 31,696 B ksram
User:   80,816 B uflash; 4 KiB usram

Three kernel backend runs:

30.1490 / 30.1480 / 30.1490 s

Three libc custom user queue runs:

15.6540 / 15.6540 / 15.6540 s

Steady state after the first executions:

Kernel test:
  Kmem 9,968 B used / 248,080 B free
  Umem 9,232 B used / 416,752 B free

After starting the libc user test:
  Kmem 10,032 B used / 248,016 B free
  Umem  9,232 B used / 416,752 B free

The remaining runs had identical current heap usage and allocation-node
counts.

3. Protected Lite (CONFIG_DISABLE_PTHREAD=y)

Build output:

Kernel: 87,232 B kflash; 31,644 B ksram
User:   49,056 B uflash; 4 KiB usram

Three kernel backend runs:

30.1490 / 30.1490 / 30.1490 s

Three predefined libc USRWORK runs without pthread support:

0.2290 / 0.2290 / 0.2290 s

Every user run reported:

wqueue_test: backend = predefined USRWORK (pthread disabled)
wqueue_test: PASS

The test queued real immediate and delayed work, pending replacement,
pending cancellation, synchronous cancellation, and callback-driven periodic
requeue. After the first kernel run, memory remained stable at:

Kmem 9,784 B used / 248,264 B free
Umem 9,216 B used / 416,768 B free

The three predefined USRWORK runs retained no additional memory.

4. PX4 Flat integration

nsh> ver all
HW arch: PX4_FMU_V6C
HW type: V6C002001
HW version: 0x002
HW revision: 0x001
PX4 git-hash: ce0460fc83231d8b1e6d6e0233bf1f2795ae7c36
PX4 version: 1.18.0 80 (17956992)
PX4 git-branch: baseline/px4-nuttx-12.12-wqueue
OS: NuttX
OS version: Release 13.0.1 (218104319)
OS git-hash: 571531fa019229bd61480f9ee5d2a52017bc1a9f
Build datetime: Aug 29 2026 16:42:38
Build uri: localhost
Build variant: default
Toolchain: GNU GCC, 10.3.1 20210824 (release)
PX4GUID: 00060000000034373938303151090027001b
MCU: STM32H7[4|5]xxx, rev. V

nsh> top once

 PID COMMAND                   CPU(ms) CPU(%)  USED/STACK PRIO(BASE) STATE FD
   0 Idle_Task                   32406 77.543   272/  768   0 (  0)  READY  3
   1 hpwork                          0  0.000   336/ 1216 249 (249)  w:sem  3
   2 lpwork                          0  0.000   336/ 1568  50 ( 50)  w:sem  3
   3 nsh_main                        0  0.000  2224/ 3152 100 (100)  w:sem  3
   4 wq:manager                      0  0.000   592/ 1240 255 (255)  w:sem  3
   5 wq:lp_default                   2  0.172  1040/ 3424 205 (205)  w:sem  3
1165 mavlink_shell                   0  0.000   808/ 2008 100 (100)  w:sem  3
 407 wq:hp_default                   7  0.648   920/ 2728 237 (237)  w:sem  3
 476 wq:SPI1                        51  4.270  1736/ 2328 253 (253)  w:sem  3
 486 wq:I2C4                         5  0.493   776/ 2272 243 (243)  w:sem  3
 671 wq:nav_and_controllers         24  2.052  1200/ 2160 242 (242)  w:sem  3
 680 wq:rate_ctrl                   27  2.326  2424/ 3072 255 (255)  w:sem  3
 681 wq:INS0                        14  1.190  1144/ 5936 241 (241)  w:sem  3
 682 wq:INS1                        13  1.154  1128/ 5936 240 (240)  w:sem  3
1145 mavlink_rcv_if0                 2  0.195  1304/ 3984 175 (175)  w:sem  5
 734 wq:ttyS4                        2  0.188  1032/ 1664 230 (230)  w:sem  3
 876 commander                       4  0.412  1528/ 3200 140 (140)  w:sig  5
 989 gps                             0  0.062  1280/ 1944 205 (205)  w:sem  4
1042 mavlink_if0                    21  1.751  1640/ 2712 100 (100)  w:sig  5
1083 navigator                       0  0.006  1312/ 2176 105 (105)  w:sem 10
1136 logger                          1  0.127  2512/ 3616 230 (230)  w:sem  3
1137 log_writer_file                 0  0.000   392/ 1152  60 ( 60)  w:sem  3
1163 mavlink_rcv_if1                 2  0.221  1728/ 3984 175 (175)  w:sem  8
1159 mavlink_if1                    79  6.584  1808/ 2800 100 (100)  READY  8
1167 top                             0  0.001  2232/ 4056 237 (237)  RUN    3

Processes: 25 total, 3 running, 22 sleeping
CPU usage: 21.85% tasks, 0.61% sched, 77.54% idle
DMA Memory: 5120 total, 0 used 0 peak
Uptime: 41.153s total, 32.407s idle

nsh> work_queue status

Work Queue: 9  threads                          RATE        INTERVAL
|__ 1) wq:rate_ctrl
|   |__ 1) control_allocator                400.8 Hz         2495 us
|   |__ 2) pwm_out                          395.1 Hz         2531 us
|   \__ 3) vehicle_angular_velocity         400.9 Hz         2495 us
|__ 2) wq:SPI1
|   |__ 1) bmi055_accel                     407.4 Hz         2454 us
|   |__ 2) bmi055_gyro                      400.7 Hz         2496 us
|   \__ 3) icm42688p                        401.6 Hz         2490 us
|__ 3) wq:I2C4
|   |__ 1) ist8310                           46.2 Hz        21623 us
|   \__ 2) ms5611                            92.5 Hz        10812 us
|__ 4) wq:nav_and_controllers
|   |__ 1) airspeed_selector                 10.0 Hz        99928 us (100000 us)
|   |__ 2) ekf2_selector                     10.0 Hz        99627 us
|   |__ 3) fw_att_control                     0.0 Hz            0 us
|   |__ 4) fw_lat_lon_control                 0.0 Hz            0 us
|   |__ 5) fw_mode_manager                    0.0 Hz            0 us
|   |__ 6) fw_rate_control                  400.8 Hz         2495 us
|   |__ 7) land_detector                     20.0 Hz        49992 us
|   |__ 8) sensors                          200.4 Hz         4991 us
|   |__ 9) vehicle_acceleration             204.0 Hz         4902 us
|   |__10) vehicle_air_data                  69.5 Hz        14397 us
|   |__11) vehicle_gps_position               3.3 Hz       299095 us
|   \__12) vehicle_magnetometer              46.3 Hz        21600 us
|__ 5) wq:INS0
|   |__ 1) ekf2                             200.3 Hz         4991 us
|   \__ 2) vehicle_imu                      200.4 Hz         4990 us
|__ 6) wq:INS1
|   |__ 1) ekf2                             200.9 Hz         4977 us
|   \__ 2) vehicle_imu                      200.9 Hz         4977 us
|__ 7) wq:hp_default
|   |__ 1) battery_status                   100.0 Hz         9999 us
|   |__ 2) board_adc                        100.0 Hz         9999 us (10000 us)
|   |__ 3) fw_autotune_attitude_control     400.8 Hz         2495 us
|   |__ 4) manual_control                     5.0 Hz       199380 us
|   |__ 5) rc_update                          0.0 Hz            0 us
|   \__ 6) tone_alarm                         0.4 Hz      2473010 us
|__ 8) wq:ttyS4
|   \__ 1) px4io                             48.3 Hz        20708 us
\__ 9) wq:lp_default
    |__ 1) cdcacm_autostart                   2.0 Hz       495727 us
    |__ 2) gyro_calibration                  50.0 Hz        19992 us (20000 us)
    |__ 3) load_mon                           2.0 Hz       499734 us (500000 us)
    |__ 4) mag_bias_estimator                50.0 Hz        19990 us (20000 us)
    |__ 5) parameters                         0.0 Hz            0 us
    \__ 6) send_event                        30.0 Hz        33315 us (33333 us)

5. PX4 Protected integration

nsh> ver all
HW arch: PX4_FMU_V6C
HW type: V6C002001
HW version: 0x002
HW revision: 0x001
PX4 git-hash: f41aec1da254de4a0c2b23bc5bda2dd242d8bd90
PX4 version: 1.18.0 80 (17956992)
PX4 git-branch: baseline/px4-nuttx-12.12-wqueue
OS: NuttX
OS version: Release 13.0.1 (218104319)
OS git-hash: 571531fa019229bd61480f9ee5d2a52017bc1a9f
Build datetime: Aug 29 2026 16:51:50
Build uri: localhost
Build variant: protected
Toolchain: GNU GCC, 10.3.1 20210824 (release)
PX4GUID: 00060000000034373938303151090027001b
MCU: STM32H7[4|5]xxx, rev. V

nsh> top once

 PID COMMAND                   CPU(ms) CPU(%)  USED/STACK PRIO(BASE) STATE FD
   0 Idle_Task                   25238 33.287   272/  768   0 (  0)  READY  3
   1 hpwork                          0  0.000   336/ 1216 249 (249)  w:sem  3
   2 lpwork                          0  0.000   336/ 1568  50 ( 50)  w:sem  3
   3 uwork                           0  0.000   376/ 2016 100 (100)  w:sem  3
   5 kwq:manager                     0  0.000   560/ 1240 255 (255)  w:sem  3
   6 kwq:lp_default                  0  0.069   864/ 3424 205 (205)  w:sem  3
   7 usr_hrt                         5  0.417   416/  968 255 (255)  w:sem  3
   8 uwq:manager                     0  0.000   568/ 1240 255 (255)  w:sem  3
 976 mavlink_shell                   0  0.000   912/ 2008 100 (100)  w:sem  3
 207 kwq:hp_default                  5  0.446   864/ 2728 237 (237)  w:sem  3
 265 kwq:SPI1                       23  1.923  1728/ 2328 253 (253)  w:sem  3
 222 uwq:lp_default                  5  0.439  1072/ 3480 205 (205)  w:sem  3
 267 kwq:I2C4                        5  0.452   768/ 2272 243 (243)  w:sem  3
 554 kwq:nav_and_controllers        29  2.476  1192/ 2160 242 (242)  w:sem  3
 556 kwq:rate_ctrl                  19  1.606  1088/ 3072 255 (255)  w:sem  3
 557 kwq:INS0                       14  1.221  1128/ 5936 241 (241)  w:sem  3
 950 mavlink_rcv_if0                10  0.868  1280/ 3984 175 (175)  w:sem  5
 567 kwq:ttyS4                       2  0.199  1032/ 1664 230 (230)  w:sem  3
 570 uwq:hp_default                  0  0.000   352/ 2784 237 (237)  w:sem  3
 595 commander                      31  2.644  1624/ 3200 140 (140)  w:sig  5
 604 uwq:rate_ctrl                  63  5.327  2424/ 3128 255 (255)  w:sem  3
 622 uwq:nav_and_controllers         2  0.186   856/ 2224 242 (242)  w:sem  3
 725 gps                             9  0.751  1344/ 1944 205 (205)  w:sem  4
 761 mavlink_if0                   101  8.423  1696/ 2712 100 (100)  w:sig  5
 827 navigator                       0  0.049  1344/ 2176 105 (105)  w:sem 10
 914 logger                         12  1.070  2576/ 3616 230 (230)  w:sem  3
 916 log_writer_file                 0  0.000   424/ 1152  60 ( 60)  w:sem  3
 959 mavlink_rcv_if1                12  1.029  1728/ 3984 175 (175)  w:sem  8
 957 mavlink_if1                   264 22.044  1840/ 2800 100 (100)  READY  8
 984 top                             0  0.001  2304/ 4056 237 (237)  RUN    3

Processes: 30 total, 3 running, 27 sleeping
CPU usage: 51.64% tasks, 15.07% sched, 33.29% idle
DMA Memory: 5120 total, 0 used 0 peak
Uptime: 43.260s total, 25.239s idle

nsh> work_queue status

User Work Queue: 4  threads                          RATE        INTERVAL
|__ 1) uwq:rate_ctrl
|   \__ 1) control_allocator                401.8 Hz         2489 us
|__ 2) uwq:nav_and_controllers
|   \__ 1) land_detector                     20.0 Hz        49990 us
|__ 3) uwq:hp_default
|   \__ 1) rc_update                          0.0 Hz            0 us
\__ 4) uwq:lp_default
    |__ 1) cdcacm_autostart                   2.0 Hz       492085 us
    |__ 2) gyro_calibration                  50.0 Hz        19999 us (20000 us)
    \__ 3) send_event                        30.0 Hz        33321 us (33333 us)

Kernel Work Queue: 8  threads                          RATE        INTERVAL
|__ 1) kwq:rate_ctrl
|   |__ 1) pwm_out                          396.6 Hz         2521 us
|   \__ 2) vehicle_angular_velocity         401.8 Hz         2489 us
|__ 2) kwq:SPI1
|   \__ 1) icm42688p                        401.6 Hz         2490 us
|__ 3) kwq:I2C4
|   |__ 1) ist8310                           46.3 Hz        21621 us
|   \__ 2) ms5611                            92.5 Hz        10812 us
|__ 4) kwq:nav_and_controllers
|   |__ 1) ekf2_selector                     10.0 Hz        99878 us
|   |__ 2) fw_rate_control                  401.8 Hz         2489 us
|   |__ 3) sensors                          200.9 Hz         4978 us
|   |__ 4) vehicle_acceleration             201.0 Hz         4976 us
|   |__ 5) vehicle_air_data                  69.5 Hz        14398 us
|   |__ 6) vehicle_gps_position               3.3 Hz       299757 us
|   \__ 7) vehicle_magnetometer              46.3 Hz        21615 us
|__ 5) kwq:INS0
|   |__ 1) ekf2                             200.9 Hz         4978 us
|   \__ 2) vehicle_imu                      200.9 Hz         4978 us
|__ 6) kwq:hp_default
|   |__ 1) battery_status                   100.0 Hz        10000 us
|   |__ 2) board_adc                        100.0 Hz         9998 us (10000 us)
|   |__ 3) manual_control                     5.0 Hz       199789 us
|   \__ 4) tone_alarm                         0.4 Hz      2654780 us
|__ 7) kwq:ttyS4
|   \__ 1) px4io                             48.2 Hz        20739 us
\__ 8) kwq:lp_default
    |__ 1) load_mon                           2.0 Hz       496279 us (500000 us)
    |__ 2) mag_bias_estimator                50.0 Hz        19990 us (20000 us)
    \__ 3) parameters                         0.0 Hz            0 us

Validation

NuttX commit-message checkpatch: pass
NuttX complete patch checkpatch: pass
git diff --check: pass
Protected rebuild after the final attr initialization fix: pass
Repeated runtime tests: no assertion, crash, reboot, or cumulative heap growth

flags = spin_lock_irqsave(&wqueue->lock);

if (!work_available(work))
for (; ; )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need for loop here?

nxsem_reset(&wqueue->sem, 0);
nxsem_reset(&wqueue->exsem, 0);

flags = spin_lock_irqsave_nopreempt(&wqueue->lock);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need lock

}

/* Get exclusive access to the work queue */
for (; ; )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need for loop

#ifndef CONFIG_DISABLE_PTHREAD
int work_queue_priority_wq(FAR struct kwork_wqueue_s *handle)
{
return work_priority((FAR struct usr_wqueue_s *)handle);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge work_priority here and remove work_priority

return -EINVAL;
}

return work_priority(&g_usrwork);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call work_queue_priority_wq

int wndx;

if (name == NULL || stack_size <= 0 || nthreads < 1 ||
(size_t)nthreads > (SIZE_MAX - sizeof(*wqueue)) /

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the cast and merge the next line

* Name: work_queue_priority_wq
****************************************************************************/

#ifndef CONFIG_DISABLE_PTHREAD

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

FAR struct usr_worker_s *worker =
(FAR struct usr_worker_s *)arg;

while (work_process(worker))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge work_process here and remove work_process

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@13022591351 please fix:

====================================================================================
Configuration/Tool: imx93-evk/bootloader
2026-08-29 14:07:43
------------------------------------------------------------------------------------
  Cleaning...
  Configuring...
  Building NuttX...
aarch64-none-elf-ld: /github/workspace/sources/nuttx/nuttx section `.rodata' will not fit in region `ocram'
aarch64-none-elf-ld: section .data LMA [00000000204e0000,00000000204e213f] overlaps section .rodata LMA [00000000204c7000,00000000204e033f]
aarch64-none-elf-ld: region `ocram' overflowed by 832 bytes
make[1]: *** [Makefile:194: nuttx] Error 1
make: *** [tools/Unix.mk:572: nuttx] Error 2
make: Target 'all' not remade because of errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Documentation Improvements or additions to documentation Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants